package com.rockwell.maze800.model;

public class LeftFirstMazeSolver implements IMazeSolver {
	private RobotCommand m_com = new RobotCommand();
	
	@Override
	public RobotCommand nextAction(RobotPosition rp, boolean beforeDetectWall) {
		
		switch (rp.location)
		{
		case LaneLeft2:
		case LaneLeft1:
		case LaneRight2:
		case LaneRight1:
		case LaneCenter:
			m_com.action = RobotAction.Jog;
			break;
		case RightTurnOnlyButTooLeft2:
		case RightTurnOnlyButTooLeft1:
		case RightTurnOnly:
			if (beforeDetectWall)
				m_com.action = RobotAction.Detect_Front_Wall;
			else
				m_com.action = RobotAction.TurnRight;
			break;
		case TRightStraightButTooLeft2:
		case TRightStraightButTooLeft1:
		case TRightStraight:
			if (beforeDetectWall)
				m_com.action = RobotAction.Detect_Front_Wall;
			else
				m_com.action = RobotAction.Jog;
			break;
		case LeftTurnOnlyButTooRight2:
		case LeftTurnOnlyButTooRight1:
		case LeftTurnOnly:
			m_com.action = RobotAction.TurnLeft;
			break;
		case TLeftStraightButTooRight2:
		case TLeftRStraightButTooRight1:
		case TLeftStraight:
			if (beforeDetectWall)
				m_com.action = RobotAction.Detect_Front_Wall;
			else
				m_com.action = RobotAction.TurnLeft;
			break;
		case TLeftRight:
			m_com.action = RobotAction.TurnLeft;
			break;
		case FourWay:
			if (beforeDetectWall)
				m_com.action = RobotAction.Detect_Front_Wall;
			else
				m_com.action = RobotAction.TurnLeft;
			break;
		case DeadEnd:
			m_com.action = RobotAction.TurnBack;
			break;
		default:
			assert(false);
			break;
		}
		
		return m_com;
	}

	@Override
	public void onJunctionPassed(RobotAction action) {
		// do nothing
	}
}
